<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
	<title>WebCópias - Nova Impressão</title>
	<link rel="shortcut icon" href="../assets/image/favicon.ico" />
	<link rel="stylesheet" href="../assets/css/styleNewWork.css" />
</h:head>
<body>
	<p:growl id="resultMessage" showDetail="true" life="4000" />
	<p:layout fullPage="true" styleClass="container">
		<p:layoutUnit position="north" size="95" resizable="false" closable="false"	collapsible="false" styleClass="header">
			<ui:include src="/form/header.xhtml"></ui:include>
		</p:layoutUnit>

		<p:layoutUnit position="west" size="200" header="Navegação" collapsible="true"	styleClass="menu" style="padding:0 !important;">
			<ui:include src="/form/menu.xhtml"></ui:include>
		</p:layoutUnit>

		<p:layoutUnit position="center" header="Minhas impressões pendentes" styleClass="content">
			<h:form id="dataGridForm"> 
			
				<p:poll interval="5" update=":dataGridForm:workDataGrid"/>
			
				<p:dataGrid var="userRequest" emptyMessage="Nenhuma impressão pendente" value="#{work.userRequestList}" columns="3"  
					rows="6" paginator="true" id="workDataGrid"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
					rowsPerPageTemplate="6,12,18" styleClass="dataGrid">  

					<f:facet name="header">
						<h:outputText rendered="#{!work.hasService}" styleClass="outputLabel"
						value="- Não é possível adicionar uma impressão enquanto não tiver nenhum serviço cadastrado" />

						<h:outputText rendered="#{!work.hasService}" styleClass="outputLabel" value="&lt;br/&gt;" escape="false" />

						<h:outputText rendered="#{!work.hasParameter}" styleClass="outputLabel"
						value="- Os parâmetros do sistema não foram cadastrados, contate o administrador do sistema" />

						<h:outputText rendered="#{!work.hasParameter}" styleClass="outputLabel" value="&lt;br/&gt;" escape="false" />

						<h:outputText rendered="#{!work.belongsDiscipline}" styleClass="outputLabel"
						value="- Seu usuário precisa pertencer a pelo menos uma disciplina para poder requisitar uma impressão" />

						<p:commandButton rendered="#{work.belongsDiscipline and work.hasService and work.hasParameter}" id="btAddWork" 
						styleClass="addWorkButton" actionListener="#{work.prepareCreateWork}"
						oncomplete="addNewWork.show()" update=":formAddWork:panelAddWork"
						value="Adicionar Impressão" icon="ui-icon-circle-plus" title="Adicionar Impressão" />
					</f:facet>

					<p:panel header="Código da tarefa: #{userRequest.central.id}" styleClass="panelGridBox" style="text-align:center">  
						<h:panelGrid columns="1" style="width:100%">  

							<p:graphicImage value="../assets/image/#{userRequest.document.documentType}.png"/> 

							<h:outputText value="Serviço: #{userRequest.serviceName}" />
							<h:outputText value="Cópias: #{userRequest.serviceName}" />
							<h:outputText value="Custo total: R$ #{userRequest.serviceCost * userRequest.central.quantityCopy}" />
							<h:outputText value="Comentário: #{userRequest.central.observation}" />
							
							<p:commandLink update=":dataGridForm:workDataGrid :resultMessage" oncomplete="confirmationCancelWork.show()" title="Cancelar impressão">  
			                    <h:outputText styleClass="ui-icon ui-icon-circle-close" style="margin:0 auto;" />   
			                    <f:setPropertyActionListener value="#{userRequest}" target="#{work.selectedRequest}"/>  
			                </p:commandLink>
						</h:panelGrid>  
					</p:panel>
				</p:dataGrid>
			</h:form>
		</p:layoutUnit>
	</p:layout>

	<p:dialog header="Criar Pedido de Impressão" widgetVar="addNewWork" resizable="false" modal="true" showEffect="fade" width="510">
		<h:form id="formAddWork" enctype="multipart/form-data">
			<h:panelGrid id="panelAddWork" columns="2" style="margin-bottom:10px">

				<h:outputLabel for="addService" value="Serviço:" />
				<p:selectOneMenu id="addService" value="#{work.selectedService}">
					<f:selectItems value="#{work.serviceMap}" />
				</p:selectOneMenu>
				
				<h:outputLabel for="addDiscipline" value="Disciplina:" />
				<p:selectOneMenu id="addDiscipline" value="#{work.selectedDiscipline}">
					<f:selectItems value="#{work.disciplineMap}" />
				</p:selectOneMenu>
				
				<h:outputLabel for="addCopyQtd" value="Quantidade de cópias:" />
				<p:spinner id="addCopyQtd" value="#{work.qtdCopy}" size="5"/>
				
				<h:outputLabel for="addComment" value="Comentátio:" />
				<p:inputTextarea id="addComment" cols="50" rows="5" value="#{work.comment}"></p:inputTextarea>

				<p:outputLabel for="addFile" value="Arquivo:"/>
				<p:fileUpload value="#{work.file}" mode="simple" id="addFile" allowTypes="/(\.|\/)(pdf|doc|png|jpg?g|docx|xls|xlsx|txt)$/"
				sizeLimit="100000" invalidFileMessage="A extensão do arquivo não é válida." invalidSizeMessage="O limite de tamanho é 10mb."/>
				
				<h:outputLabel for="addDocumentDescription" value="Descrição do documento:" />
				<p:inputText id="addDocumentDescription" value="#{work.documentDescription}"/>
				
				<f:facet name="footer">
					<p:separator/>
					<p:commandButton action="#{work.addWork}" oncomplete="addNewWork.hide()" ajax="false" value="Confirmar" />
					<p:commandButton oncomplete="addNewWork.hide()" value="Cancelar" />
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>
	
	<h:form>  
	    <p:confirmDialog id="confirmCancelWork" message="Deseja Cancelar essa impressão?" header="Cancelar impressão" severity="alert" widgetVar="confirmationCancelWork">  
	        <p:commandButton id="confirmCancel" value="Sim" onclick="confirmationCancelWorkk.hide()" update=":dataGridForm:workDataGrid :resultMessage" actionListener="#{work.cancelWork}" />  
	        <p:commandButton id="decline" value="Não" onclick="confirmationCancelWork.hide()" />   
	    </p:confirmDialog>  
	</h:form>
	
	<p:dialog header="Alterar Conta" widgetVar="updateAccount" resizable="false" modal="true" showEffect="slide" width="500">
		<h:form prependId="false">
			<h:panelGrid id="infosLivro" columns="2" style="margin-bottom:10px" >
				<h:outputLabel for="updateRegistration" value="Matrícula:" />
				<p:inputText value="#{user.loggedUser.registration}" id="updateRegistration" disabled="true" />

				<h:outputLabel for="updateName" value="Nome:" />
				<p:inputText value="#{user.loggedUser.name}" id="updateName" />

				<h:outputLabel for="updatePassword" value="Senha:" />
				<h:inputSecret value="#{user.loggedUser.password}" id="updatePassword" styleClass="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all ui-state-hover" />

				<h:outputLabel for="updateEmail" value="E-mail:" />
				<p:inputText value="#{user.loggedUser.email}" id="updateEmail" required="false" />

				<h:outputLabel for="updatePhoto" value="Foto:" />
				<p:inputText value="#{user.loggedUser.photo}" id="updatePhoto" required="false" />

				<f:facet name="footer">
					<p:separator/>
					<p:commandButton oncomplete="updateAccount.hide()" actionListener="#{user.selfUpdateUser}" update=":resultMessage" value="Salvar"/>
				</f:facet>
			</h:panelGrid>
		</h:form>
	</p:dialog>
</body>
</html>